/**
 * 
 */
package com.hs.core.db;

import java.util.Map;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;


/**
 * @author shl
 *
 * Jan 8, 2011
 */
public  class JdbcTemplateUtil {
	public static Logger log = Logger.getLogger(JdbcTemplateUtil.class.getName());
	
	private static final int MAX_EXPORT_NUM = 20000;
	
	private static JdbcTemplateUtil _inst = new JdbcTemplateUtil();
	
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
	public static JdbcTemplateUtil getInst(){
		
		return _inst;
	}
	private int MAXNATIVENUM = 10;
	 
	public JdbcTemplate getJdbcTemplate(String dburl,String username,String password){
		JdbcTemplate jdbcTemplate = new JdbcTemplate();
		DataSource ds = initDataSourse(dburl,username,password);
		jdbcTemplate.setDataSource(ds); 
		return jdbcTemplate;
	}
	protected JdbcTemplateUtil(){
		log.info("init"); 
		
	}
	 
	protected Map paramMap; 
	DataSource ds;
	
	public DataSource initDataSourse(String dburl,String username,String pwd){
		BasicDataSource ds = new BasicDataSource();
		ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
		ds.setUrl(dburl);
		ds.setPassword(pwd);
		ds.setUsername(username);
		ds.setMaxActive(MAXNATIVENUM);
		ds.setMaxIdle(20);
		ds.setMaxWait(1000);
		ds.setDefaultAutoCommit(true);
		ds.setDefaultReadOnly(true);
		return (DataSource)ds;
	}

}
